/*
 * Copyright 2009 StructBeans Project
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the 
 * License for the specific language governing rights and limitations under 
 * the License.
 */

package org.structbeans.core;


public class Attribute {
	
	private FieldType type;
	private Long length;
	private Integer index;
	private String name;
	
	private Class<?> attributeClass;
	
	public Attribute() {

	}


	public Attribute(FieldType type, Long length, Integer index, String name,
			Class<?> attributeClass) {
		super();
		this.type = type;
		this.length = length;
		this.index = index;
		this.name = name;
		this.attributeClass = attributeClass;
	}

	public FieldType getType() {
		return type;
	}

	public void setType(FieldType type) {
		this.type = type;
	}

	public Long getLength() {
		return length;
	}

	public void setLength(Long length) {
		this.length = length;
	}

	public Integer getIndex() {
		return index;
	}

	public void setIndex(Integer index) {
		this.index = index;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	private String getTailAccessorMethodName() {
		return new StringBuffer(name.substring(0, 1).toUpperCase()).append(name.substring(1)).toString();
	}
	
	public String getExpectedGetterName() {
		return new StringBuffer("get").append(getTailAccessorMethodName()).toString();
	}
	
	public String getExpectedSetterName() {
		return new StringBuffer("set").append(getTailAccessorMethodName()).toString();
	}

	public Class<?> getAttributeClass() {
		return attributeClass;
	}

	public void setAttributeClass(Class<?> attributeClass) {
		this.attributeClass = attributeClass;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((attributeClass == null) ? 0 : attributeClass.hashCode());
		result = prime * result + ((index == null) ? 0 : index.hashCode());
		result = prime * result + ((length == null) ? 0 : length.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Attribute other = (Attribute) obj;
		if (attributeClass == null) {
			if (other.attributeClass != null)
				return false;
		} else if (!attributeClass.equals(other.attributeClass))
			return false;
		if (index == null) {
			if (other.index != null)
				return false;
		} else if (!index.equals(other.index))
			return false;
		if (length == null) {
			if (other.length != null)
				return false;
		} else if (!length.equals(other.length))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
	
	

	
	
}